unit Root;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls,registry, ToolWin;

type
  TfmRoot = class(TForm)
    sbBottom: TStatusBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormHide(Sender: TObject);
  private
    { Private declarations }
    sFParam: String;
    function GetFParam: String;
    procedure SetFParam(fparam:String);
    procedure WMGetMinMaxInfo(var M:TWMGetMinMaxInfo);
                            message WM_GETMINMAXINFO;
  protected
    RegIni:TRegIniFile;
    MinHeight,MinWidth:integer;

  public
    { Public declarations }
    AutoDestroy:Boolean;
    property FParam: String read GetFParam write SetFParam;
  end;

var
  fmRoot: TfmRoot;

implementation

uses InvTypes;

{$R *.DFM}
function TfmRoot.GetFParam: String;
begin
  GetFParam:=sFParam;
end;

procedure TfmRoot.SetFParam(fparam:String);
begin
  sFParam:=fparam;
end;

procedure TfmRoot.FormCreate(Sender: TObject);
Var
  t,l: Integer;
begin
  FParam:=IntToStr(IDCompany);
  if Application.Title<>'' then begin
    RegIni:=TRegIniFile.Create('Software\'+gTitle);
    t:=RegIni.ReadInteger (Name,'Top',Top);
    l:=RegIni.ReadInteger(Name,'Left',Left);
    Width:=RegIni.ReadInteger(Name,'Width',Width);
    Height:=RegIni.ReadInteger(Name,'Height',Height);
    if t>Screen.Height then t:=Round((Screen.Height-Height)/2);
    if l>Screen.Width then l:=Round((Screen.Width-Width)/2);
    if t<0 then t:=0; if l<0 then l:=0;
    Top:=t; Left:=l;
  end else RegIni:=nil;
  MinHeight:=0;
  MinWidth:=0;
  sbBottom.Panels[0].Text:=FullUserName;
  AutoDestroy:=true;
end;

procedure TfmRoot.FormDestroy(Sender: TObject);
begin
  if RegIni<>nil then begin
    RegIni.WriteInteger(Name,'Width',Width);
    RegIni.WriteInteger(Name,'Height',Height);
    RegIni.WriteInteger(Name,'Top',Top);
    RegIni.WriteInteger(Name,'Left',Left);
    RegIni.Free;
  end;
end;

procedure TfmRoot.WMGetMinMaxInfo(var M:TWMGetMinMaxInfo);
begin
  m.MinMaxInfo^.ptMaxTrackSize.x:=Screen.Width;
  m.MinMaxInfo^.ptMaxTrackSize.y:=Screen.Height;
  if MinHeight<>0 then begin
    if (ClientHeight<>0) then
      m.MinMaxInfo^.ptMinTrackSize.y:=Height-ClientHeight+MinHeight
    else m.MinMaxInfo^.ptMinTrackSize.y:=MinHeight;
  end;
  if MinWidth<>0 then begin
    if (ClientWidth<>0) then
      m.MinMaxInfo^.ptMinTrackSize.x:=Width-ClientWidth+MinWidth
    else m.MinMaxInfo^.ptMinTrackSize.x:=MinWidth;
  end;
end;

procedure TfmRoot.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if AutoDestroy then Action := caFree
  else Action := caHide;
end;

procedure TfmRoot.FormHide(Sender: TObject);
begin
  if AutoDestroy then Release;
end;

end.
